//-----------------------------------------------------------------------------
// Bend2D - Physics Engine
// Roberto Bender <beto.bender@gmail.com>
// Description: 
// Date: 15/10/2010
//-----------------------------------------------------------------------------
#include "log.h"
#include <iomanip>
using namespace bend2d;

#ifdef BEND2DLOG

Log *Log::m_Intance = NULL;

Log::Log() :
    m_LogLevel(eLogInfo),
    m_File(NULL)
{
     m_File = new ofstream("./bend2d.log");
     if(m_File->good() == false)
     {
         delete m_File;
         m_File = NULL;
     }
     m_Timer.Start();
}

void Log::SetLogLevel(logLevel level)
{
     m_LogLevel = level;
}

void Log::Write(logLevel level, const stringstream& stream)
{
     if(m_File != NULL)
     {
         if(m_LogLevel >= level)
         {
             (*m_File) << "[" << setw(9) << setfill('0') << m_Timer.GetTime() << " ms]" << stream.str() << "\n" << flush;
         }
     }
}
 
Log* Log::GetInstance()
{
     if(m_Intance == NULL)
         m_Intance = new Log();
     return m_Intance;
}

#endif
